//商品分类相关接口
import { AttrResponseData, CategoryResponseData, Attr } from './types';

// 统一接口管理
enum API {
  C1_URL = '/admin/product/getCategory1',
  C2_URL = '/admin/product/getCategory2',
  C3_URL = '/admin/product/getCategory3',
  ATTRINFO_URL = '/admin/product/attrInfoList',
  ADD_ATTRINFO_URL = '/admin/product/saveAttrInfo',
  DELETE_ATTRINFO_URL = '/admin/product/deleteAttr',
}

// 获取一级分类接口
export const reqC1 = () => {
  return request.get<any, CategoryResponseData>(API.C1_URL);
};
// 获取二级分类接口
export const reqC2 = (id: number | string) => {
  return request.get<any, CategoryResponseData>(API.C2_URL + `/${id}`);
};
// 获取三级分类接口
export const reqC3 = (id: number | string) => {
  return request.get<any, CategoryResponseData>(API.C3_URL + `/${id}`);
};
// 根据三级分类id获取商品属性
export const reqGetAttrInfo = (category1Id: string | number, category2Id: string | number, category3Id: string | number) => {
  return request.get<any, AttrResponseData>(API.ATTRINFO_URL + `/${category1Id}/${category2Id}/${category3Id}`);
};
// 新增或者修改商品属性值
export const reqAddAttrInfo = (data: Attr) => {
  return request.post<any, any>(API.ADD_ATTRINFO_URL, data);
};
// 删除改商品属性
export const reqDeleteAttrInfo = (attrId: number) => {
  return request.delete<any, any>(API.DELETE_ATTRINFO_URL + `/${attrId}`);
};
